package com.yygo.webapp.controller;

import com.yygo.service.LoanRequestManager;
import com.yygo.model.Feedback;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ExtendedModelMap;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/feedbacks*")
public class FeedbackController {
    private LoanRequestManager loanRequestManager;

    @Autowired
    public void setLoanRequestManager(@Qualifier("loanRequestManager") LoanRequestManager loanRequestManager) {
        this.loanRequestManager = loanRequestManager;
    }

    @RequestMapping(method = RequestMethod.GET)
    public Model handleRequest(@RequestParam(required = true, value = "reqId") Long reqId)
    throws Exception {
        Model model = new ExtendedModelMap();
        model.addAttribute(loanRequestManager.loadWholeLoanRequest(reqId));
        //model.addAttribute(loanRequestManager.getFeedbacks(reqId));
        return model;
    }

    @ModelAttribute
    protected Feedback showForm(HttpServletRequest request)
            throws Exception {
        return new Feedback();
    }
}
